# Maintainer: Sébastien Luttringer <seblu@archlinux.org>
# Contributor: Kaiting Chen <kaitocracy@gmail.com>
# Contributor: Tilman Blumenbach <tilman (at) ax86 (dot) net>

pkgname=netperf
pkgver=2.7.0
pkgrel=6
pkgdesc='Benchmarking tool for many different types of networking'
url='https://github.com/HewlettPackard/netperf/'
license=('custom')
arch=('loong64' 'x86_64')
depends=('glibc' 'libsmbios' 'lksctp-tools')
install=netperf.install
source=("https://github.com/HewlettPackard/netperf/archive/$pkgname-$pkgver.tar.gz"
        'netserver.service'
        '001-fix-inlining.patch')
sha224sums=('6ab49c94d6231d4848bc43c8d56ad4a2611862f800a61009f3b2f2fe'
            'c5c48a480d62e82d1e65cc3ef8472864bf12d2cc527d6a9c12dca613'
            '7a30925a46ab5e40ccc2b966a5d7e57a15967b9116c8773cd75030f5')

prepare() {
  cd netperf-netperf-$pkgver
  # apply patch from the source array (should be a pacman feature)
  local src
  for src in "${source[@]}"; do
    src="${src%%::*}"
    src="${src##*/}"
    [[ $src = *.patch ]] || continue
    msg2 "Applying patch $src..."
    patch -Np1 < "../$src"
  done
  :
}

build() {
  cd netperf-netperf-$pkgver
  CFLAGS+=' -fcommon' # https://wiki.gentoo.org/wiki/Gcc_10_porting_notes/fno_common
  ./configure \
    --prefix=/usr \
    --enable-demo \
    --enable-unixdomain \
    --enable-dccp \
    --enable-sctp
  make
}

package() {
  cd netperf-netperf-$pkgver
  make DESTDIR="$pkgdir" install
  # license
  install -D -m 644 COPYING "$pkgdir/usr/share/licenses/$pkgname/COPYING"
  # systemd
  install -D -m 644 {..,"$pkgdir"/usr/lib/systemd/system}/netserver.service
}

# vim:set ts=2 sw=2 et:
